package planit.view.wrappers;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import planit.model.Event;
import planit.model.Group;
import planit.model.Person;

@SuppressWarnings("serial")
public class ModelCellRenderer extends JLabel implements ListCellRenderer {

	public Component getListCellRendererComponent(
			JList list,
			Object value,            // value to display
			int index,               // cell index
			boolean isSelected,      // is the cell selected
			boolean cellHasFocus)    // the list and the cell have the focus
	{
		String name = "";
		if (value.getClass() == new PersonWrapper(new Person("temp")).getClass()) {
			PersonWrapper p = (PersonWrapper)value;
			name = p.getText();
		} else if (value.getClass() == new GroupWrapper(new Group("temp")).getClass()) {
			GroupWrapper g = (GroupWrapper)value;
			name = g.getText();
		} else if (value.getClass() == new EventWrapper(new Event()).getClass()) {
			EventWrapper e = (EventWrapper)value;
			name = e.getText();
		}
		setText(name);
		if (isSelected) {
			setBackground(Color.DARK_GRAY);
			setForeground(Color.white);
		}
		else {
			setBackground(Color.white);
			setForeground(Color.black);
		}
		setEnabled(list.isEnabled());
		setFont(list.getFont());
		setOpaque(true);
		return this;
	}
}
